<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="com.hilaver.dzmis.Constants"%>
<%@ page import="com.hilaver.dzmis.service.impl.CtServiceImpl"%>
<%@ page import="com.hilaver.dzmis.service.impl.ProcurementServiceImpl"%>
<%@ page import="com.hilaver.dzmis.service.impl.I18nServiceImpl"%>
<%@ page import="com.hilaver.dzmis.codetable.CtBrand"%>
<%@ page import="com.hilaver.dzmis.codetable.*"%>
<%@ page import="com.hilaver.dzmis.procurement.Procurement"%>
<%@ page import="com.hilaver.dzmis.product.ProductIdentification"%>
<%@ page import="com.hilaver.dzmis.product.ProductOrderItem"%>
<%@ page import="com.hilaver.dzmis.product.ProductAccessoryButton"%>
<%@ page import="com.hilaver.dzmis.product.ProductAccessoryZip"%>
<%@ page import="com.hilaver.dzmis.product.ProductYarn"%>
<%@ page import="com.hilaver.dzmis.product.ProductAccessoryOthers"%>
<%@ page import="com.hilaver.dzmis.basicinfo.BiAccessoryButton"%>
<%@ page import="com.hilaver.dzmis.web.servlet.AbstractBaseServlet" %>
<%
	Integer id = Integer.parseInt(request.getParameter("id"));
	CtServiceImpl cs = new CtServiceImpl();
	ProcurementServiceImpl ps = new ProcurementServiceImpl();
	I18nServiceImpl i18n = new I18nServiceImpl();
	Locale locale = (Locale) request.getSession().getAttribute(
			Constants.SESSION_LOCALE);
	ps.setLocale(locale);
	ps.setRealFileDir(AbstractBaseServlet.UPLOAD_TEMP_REAL_DIR);
	Procurement procurement = ps.getObj(id);
	Set<ProductIdentification> piSet = procurement
			.getProductIndentifications();
	List<ProductIdentification> piSortedList = ps.sortByCustomer(piSet);
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
<link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" />
<style type="test/css">

</style>
<title><%=procurement.getName()%>--<%=i18n.getShortMessage(locale, "ui.procurement.order") %></title>
</head>
<body>
<% for(ProductIdentification pi : piSortedList){ %>
<table cellspacing="0" id="the-table" style="width: 100%;">
	<tr>
		<td colspan="11" style="background:#eeeeee;text-align: center;">
			<b><%=pi.getBiFranceCustomer().getName() %>--<%=pi.getBiFranceCustomer().getDepartment()==null?"":pi.getBiFranceCustomer().getDepartment() %>&nbsp;&nbsp;&nbsp;&nbsp;<%=i18n.getShortMessage(locale, "ui.productidentification.ordernumber") %>&nbsp;&nbsp;&nbsp;&nbsp;<%=pi.getOrderNumber() %></b>
		</td>
	</tr>
	<tr>
		<td style="background:#eeeeee;text-align: center; width: 180px;">
			<b><%=i18n.getShortMessage(locale, "ui.reference.reference") %></b>
		</td>
		<td style="background:#eeeeee;text-align: center;width: 120px;">
			<b><%=i18n.getShortMessage(locale, "message.edit.collar") %></b>
		</td>
		<td style="background:#eeeeee;text-align: center;width: 180px;">
			<b><%=i18n.getShortMessage(locale, "ui.productidentification.yarn") %></b>
		</td>
		<td style="background:#eeeeee;text-align: center;width: 80px;">
			<b><%=i18n.getShortMessage(locale, "ui.order.color") %></b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b>S</b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b>M</b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b>L</b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b>XL</b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b>XXL</b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b>XXXL</b>
		</td>
		<td style="background:#eeeeee;text-align: center;">
			<b><%=i18n.getShortMessage(locale, "message.list.total") %></b>
		</td>
	</tr>
	<% Set<ProductOrderItem> poiSet = pi.getProductOrderItems();
	   int i = 0;
	   int sTotal = 0;
	   int mTotal = 0;
	   int lTotal = 0;
	   int xlTotal = 0;
	   int xxlTotal = 0;
	   int xxxlTotal = 0;
	   int total = 0;
	   for(ProductOrderItem poi : poiSet){
	%>
		<tr>
			<%if( i == 0){%>
				<td rowspan="<%=poiSet.size() %>" style="text-align: center; vertical-align: middle;">
					<%=pi.getReference() %><br/>
					<img width="100px" src="../../_temp/<%=pi.getPhotoName()==null?"noimage.gif":pi.getPhotoName() %>"/>
				</td>
				<td rowspan="<%=poiSet.size()%>" style="text-align: center; vertical-align: middle;">
					<%=cs.getDescription(CtCollarType.class.getName(), pi.getCtCollarType(), locale)%>
				</td>
				<td rowspan="<%=poiSet.size() %>" style="text-align: center; vertical-align: middle;">
					<%
						Set<ProductYarn> pySet = pi.getProductYarns();
						for(ProductYarn py : pySet){
							out.print(py.getFil() + "&nbsp;&nbsp;");
							out.print(py.getBiYarn().getReference() + "&nbsp;&nbsp;");
							out.print(cs.getDescription(CtMaterialType.class.getName(), py.getBiYarn().getCtMaterialType(), locale));
							break;
						}
					%>
				</td>
			<%}%>
			<td style="text-align: center;">
				<%=poi.getColorNumber() %>
			</td>
			<td style="text-align: center;">
				<%
				  sTotal += poi.getAmountS();
				  out.print(poi.getAmountS());
				%>
			</td>
			<td style="text-align: center;">
				<%
				  mTotal += poi.getAmountM();
				  out.print(poi.getAmountM());
				 %>
			</td>
			<td style="text-align: center;">
				<%
					lTotal += poi.getAmountL();
					out.print(poi.getAmountL());
				%>
			</td>
			<td style="text-align: center;">
				<%xlTotal += poi.getAmountXl();
					out.print(poi.getAmountXl()); %>
			</td>
			<td style="text-align: center;">
				<%xxlTotal += poi.getAmountXxl();
					out.print(poi.getAmountXxl()); %>
			</td>
			<td style="text-align: center;">
				<%xxlTotal += poi.getAmountXxxl();
					out.print(poi.getAmountXxxl()); %>
			</td>
			<td style="text-align: center;" class="x-grid3-td-total">
				<% 
					total += poi.getTotal();
					out.print(poi.getTotal());
				%>
			</td>
		</tr>
	<%i++;} %>
		<tr>
			<td style="text-align: right;" colspan="4">
				<b><%=i18n.getShortMessage(locale, "message.list.total") %></b>
				&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			</td>
			<td style="text-align: center;" class="x-grid3-summary-row">
				<%=sTotal%>
			</td>
			<td style="text-align: center;" class="x-grid3-summary-row">
				<%=mTotal%>
			</td>
			<td style="text-align: center;" class="x-grid3-summary-row">
				<%=lTotal%>
			</td>
			<td style="text-align: center;" class="x-grid3-summary-row">
				<%=xlTotal%>
			</td>
			<td style="text-align: center;" class="x-grid3-summary-row">
				<%=xxlTotal%>
			</td>
			<td style="text-align: center;" class="x-grid3-summary-row">
				<%=xxlTotal%>
			</td>
			<td style="text-align: center;" class="x-grid3-total">
				<%=total%>
			</td>
		</tr>
</table>
<br/>
<%} %>
</body>
</html>